home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 12992 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.0 KB

  1. Path: solon.com!not-for-mail
  2. From: seebs@solutions.solon.com (Peter Seebach)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: help with strcmp
  5. Date: 3 Apr 1996 15:05:49 -0600
  6. Organization: Usenet Fact Police (Undercover)
  7. Message-ID: <4jup7d$8s5@solutions.solon.com>
  8. References: <4jpiek$lp6@blaze.cs.jhu.edu> <DpAI6o.2Cq@iquest.net>
  9. NNTP-Posting-Host: solutions.solon.com
  10.  
  11. In article <DpAI6o.2Cq@iquest.net>, Doug Miller <dlmiller@iquest.net> wrote:
  12. >I don't notice any place where you have allocated storage for fp prior to
  13. >attempting to transfer data to it.
  14.  
  15. I don't notice any place where he attempts to transfer data to it.
  16.  
  17. Could you please check your work a bit more carefully before posting?  You're
  18. obviously not stupid, and you give some very good advice, but you periodically
  19. miss the point of a question entirely, or get the entire context of a
  20. statement wrong; I think you're posting a bit faster than you're reading the
  21. code.
  22.  
  23. >lasher@hops.cs.jhu.edu (John E. Davis) wrote:
  24.  
  25. >>handle = fopen(argv[1], "r");
  26.  
  27. >>while(!feof(handle)) {
  28.  
  29. This is bad - not only is it using feof() backwards, but handle has not been
  30. checked in case it didn't get opened.  That would cause a core dump right
  31. here.
  32.  
  33. Once again: feof() informs you only that the last read failed; it doesn't
  34. belong before a read.
  35.  
  36. >>    fp = fgets(data, 40, handle);
  37.  
  38. This does not attempt to transfer data into fp; it assigns fp to point to
  39. the return of fgets, which could be either data (which is valid) or NULL,
  40. in which case...
  41.  
  42. >>    if ( strcasecmp(fp, "<action>\n") == 0)  /* the coredump is here */
  43.  
  44. This would make perfect sense if fgets fails.  Unfortunately, the original
  45. poster is testing for EOF before it happens, not after it happens, and would
  46. not notice a failure here.
  47.  
  48. -s
  49. -- 
  50. Peter Seebach - seebs@solon.com - Copyright 1996 Peter Seebach.
  51. C/Unix wizard -- C/Unix questions? Send mail for help.  No, really!
  52. FUCK the communications decency act.  Goddamned government.  [literally.]
  53. The *other* C FAQ - http://www.solon.com/~seebs/c/c-iaq.html
  54.